//
//  HouseTypeInfoCommentViewModel.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/4/8.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "HouseTypeInfoCommentViewModel.h"
#import "LayoutCommentsTableViewCellModel.h"
#import "HouseTypeInfoView.h"
#import "SyncTimer.h"
//#import "UniversalTableViewController.h"

@implementation HouseTypeInfoCommentViewModel

#pragma mark - Delegate NetworkingBaseManagerAPISuccessCallbackDelegate
- (void)manager:(NetworkingBaseManager *)manager callAPIDidSuccessWithParams:(NSDictionary *)responseParams{
    DDLogInfo(@"查看户型评论网络返回数据：%@",[responseParams description]);
    NSArray *dataArray = [responseParams objectForKey:@"data"];
    NSMutableArray *cellModels = [LayoutCommentsTableViewCellModel mj_objectArrayWithKeyValuesArray:dataArray];
    
    for (LayoutCommentsTableViewCellModel *cellModel in cellModels) {
        DDLogInfo(@"时间戳：%lld",[cellModel.date longLongValue]);
        cellModel.date = [SyncTimer timeStampToTimeString:[cellModel.date longLongValue]];
        DDLogInfo(@"转换后时间：%@",cellModel.date);
    }
    
    if (_isShowMore) {
        
//        UniversalTableViewController *universalTableViewController = self.viewObject;
//        universalTableViewController.models = cellModels;
    }else{
        
        HouseTypeInfoView *houseTypeInfoView = self.viewObject;
        houseTypeInfoView.layoutCommentsTableViewCellModels = cellModels;
    }
    
    
}

#pragma mark - Public
- (void)loadRequest{
    self.manager = [NetworkingManagerFactory generateNormalManager];
    RequestGenerator *requestGenerator = [RequestGenerator sharedInstance];
    self.manager.apiName = [requestGenerator generateCommonApiWithName:[NSString stringWithFormat:@"projects/%ld/layouts/%ld/comments",[AppContext sharedInstance].projectId,(long)self.layoutId]];
    self.manager.params = self.postObject;
    self.manager.requestType = HTTP_GET;
    self.manager.successDelegate = self;
    self.manager.validator = self;
    [self.manager loadRequest];
}

- (void)setUpMJModel{
    [LayoutCommentsTableViewCellModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
        return @{
                 @"layoutId" : @"id",
                 @"avatarURL" : @"picture",
                 @"startCount" : @"level",
                 @"comment" : @"content",
                 @"positiveCount" : @"goodReviewsCount",
                 @"negativeCount" : @"badReviewsCount"
                 };
    }];
}

@end
